package test.impl;

import test.IfElseDemo;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;

/**
 * @author Jason Wilson
 * @description TODO
 * @date 2024-05-2024/5/11-13:42
 */
public class IfElseDemoThree implements IfElseDemo {

    @Override
    public BigDecimal calculate(BigDecimal input) {
        // 异常处理：检查输入是否为空或为零
        if (input == null || input.compareTo(BigDecimal.ZERO) == 0) {
            throw new IllegalArgumentException("输入值不能为空且不能为零");
        }
        // 指定精度：这里以保留2位小数为例
        MathContext mathContext = new MathContext(2, RoundingMode.HALF_UP);
        return input.divide(BigDecimal.valueOf(2), 2, RoundingMode.HALF_UP);
    }
}
